import java.awt.Point;
import java.util.ArrayList;

public class Human extends Agent {

	private static long lastId;



	public Human(Point p) {

		super(p);
		lastId++;
		setId(lastId);
	}


	@Override
	public MapObjectType getType() {
		return MapObjectType.Human;
	}

	@Override
	public void makeMove() {
		Action a = getProvider().decide();
		if (a.getEvokerType() == MapObjectType.Human) {
			switch (a.getName()) {
			case "move":
				if (a.getDirection() != null) {
					this.move(a.getDirection());
				} else {
					System.err.println("Move action requires direction");
				}
				break;
			case "replenish":

				this.replenish();

				break;
			case "fight":
			{
				this.fight(a.getEvokerId()); //?
			}
				break;
			default:

				break;
			}
		} else if(a.getEvokerType()==MapObjectType.NO_OBJECT){
			// TODO
		} else {

		}


		
	}
	
	public void fight(long id) {
		
		MapObject object = Main.getMap().getObjectOfId(id);
		
		if (isEnemy(object)) {
			Agent agent = (Agent) object;

			if(this.getEnergy() > agent.getEnergy())
			{
				agent.kill();
			}
			else
			{
				if(agent.getType() == MapObjectType.Zombie)
				{
					if(Math.random() > 0.5)
					{
						this.turnUndead();
					}
					else
					{
						this.kill();
						agent.replenish();
					}
				}
				else
					this.kill();
			}
		}
	}
	

	public boolean isEnemy(MapObject wo) {
		Agent agent = (Agent) wo;
		if(agent.getType() != MapObjectType.Human)
			return true;
		else
			return false;
	}

}
